package com.kitty.annotation.action;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class JsonController {
	
	@RequestMapping(value = "/json/js", method = RequestMethod.GET)
	public void processRequest(PrintWriter out) {
		out.println(this.getJson());
		out.flush();
		out.close();
	}
	
	private String getJson() {
		List<String> jsonList = new ArrayList<String>();//Arrays.asList("first","second","third","fourth","fifth");
		jsonList.add("first");
		jsonList.add("second");
		jsonList.add("third");
		
		JSONArray jsonArray = JSONArray.fromObject(jsonList);
		
		//System.out.println(jsonArray);
		/*
		Map<String,String> first = new HashMap<String,String>();
		first.put("mosquito_id", "1");
		first.put("mosquito_name", "abcde");
		Map<String,String> second = new HashMap<String,String>();
		second.put("mosquito_id", "2");
		second.put("mosquito_name", "ffffff");
		Map<String,String> third = new HashMap<String,String>();
		third.put("mosquito_id", "3");
		third.put("mosquito_name", "gggggg");
		List<Map<String,String>> mapList = Arrays.asList(first,second,third);
		
		
		jsonArray = JSONArray.fromObject(mapList);
		*/
		
		return jsonArray.toString();
	}
	
}
